listitemmanager: Handle selection-changes properly
authorMatthias Clasen <mclasen@redhat.com>
Sat, 6 Jun 2020 12:34:46 +0000 (08:34 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 6 Jun 2020 12:36:11 +0000 (08:36 -0400)
The selection model will only emit one of items-changed
or selection-changed, so when we handle an items-changed,
we must assume that selection state may have changed for
any of the newly added items.

This fixes lingering selection state in the visible range
if you change the sorting of the colors demo.

Fixes: #2827
gtk/gtklistitemmanager.c

index ef0570d45aaae6f301fa2a4a973dcc3316f8ed2d..e08592bca8ffdedd68bfd8594eab4552e2d8acc6 100644 (file)
@@ -395,6 +395,7 @@ gtk_list_item_manager_add_items (GtkListItemManager *self,
 
   if (item == NULL || item->widget)
     item = gtk_rb_tree_insert_before (self->items, item);
+
   item->n_items += n_items;
   gtk_rb_tree_node_mark_dirty (item);
 
@@ -569,6 +570,12 @@ gtk_list_item_manager_ensure_items (GtkListItemManager *self,
     gtk_list_item_manager_release_list_item (self, NULL, widget);
 }
 
+static void
+gtk_list_item_manager_model_selection_changed_cb (GListModel         *model,
+                                                  guint               position,
+                                                  guint               n_items,
+                                                  GtkListItemManager *self);
+
 static void
 gtk_list_item_manager_model_items_changed_cb (GListModel         *model,
                                               guint               position,
@@ -735,6 +742,8 @@ gtk_list_item_manager_model_items_changed_cb (GListModel         *model,
 
   g_hash_table_unref (change);
 
+  gtk_list_item_manager_model_selection_changed_cb (model, position, added, self);
+
   gtk_widget_queue_resize (self->widget);
 }